package com.pd.backend.service.impl;

import com.pd.backend.entity.PdTruckLicense;
import com.pd.backend.dao.PdTruckLicenseDao;
import com.pd.backend.service.PdTruckLicenseService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 车辆行驶证表(PdTruckLicense)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:36
 */
@Service("pdTruckLicenseService")
public class PdTruckLicenseServiceImpl implements PdTruckLicenseService {
    @Resource
    private PdTruckLicenseDao pdTruckLicenseDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdTruckLicense queryById(String id) {
        return this.pdTruckLicenseDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdTruckLicense 筛选条件
     * @param pageRequest    分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdTruckLicense> queryByPage(PdTruckLicense pdTruckLicense, PageRequest pageRequest) {
        long total = this.pdTruckLicenseDao.count(pdTruckLicense);
        return new PageImpl<>(this.pdTruckLicenseDao.queryAllByLimit(pdTruckLicense, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdTruckLicense 实例对象
     * @return 实例对象
     */
    @Override
    public PdTruckLicense insert(PdTruckLicense pdTruckLicense) {
        this.pdTruckLicenseDao.insert(pdTruckLicense);
        return pdTruckLicense;
    }

    /**
     * 修改数据
     *
     * @param pdTruckLicense 实例对象
     * @return 实例对象
     */
    @Override
    public PdTruckLicense update(PdTruckLicense pdTruckLicense) {
        this.pdTruckLicenseDao.update(pdTruckLicense);
        return this.queryById(pdTruckLicense.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.pdTruckLicenseDao.deleteById(id) > 0;
    }
}
